package cool.taomu.software.fig.web.config;

import java.util.HashSet;
import java.util.Set;

import cool.taomu.software.fig.web.core.WebSocketServer;
import jakarta.websocket.Endpoint;
import jakarta.websocket.server.ServerApplicationConfig;
import jakarta.websocket.server.ServerEndpointConfig;

public class WebsocketConfig implements ServerApplicationConfig {

	@Override
	public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> scanned) {

		Set<ServerEndpointConfig> result = new HashSet<>();

		if (scanned.contains(WebSocketServer.class)) {
			result.add(ServerEndpointConfig.Builder.create(WebSocketServer.class, "/websocket.servlet").build());
		}

		return result;
	}

	@Override
	public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {

		Set<Class<?>> result = new HashSet<>();

		for (Class<?> clazz : scanned) {
			if (clazz.getPackage().getName().startsWith("cool.taomu.software.fig.web.controller")) {
				result.add(clazz);
			}
		}

		return result;
	}

}